Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

etherGC.sol +reputationGC.sol #756

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft

etherGC.sol +reputationGC.sol #756

wants to merge 7 commits into from

Conversation

orenyodfat
Copy link
Contributor

No description provided.

@dkent600
Copy link
Contributor

dkent600 commented May 22, 2020

Can you spell out "GC" in the contract name? No idea what it means...


/**
* @dev initialize
* @param _avatar the avatar to mint reputation from
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bit a confusing comment

contract EtherGC {
using SafeMath for uint256;

uint256 public constraintPeriodWindow; //a static window
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe call it "periodLength"? and add in the comment that the unit is blocks

uint256 public constraintPeriodWindow; //a static window
uint256 public amountAllowedPerPeriod;
address public avatar;
uint256 public latestEthBalance;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what this is fore, this is just set in the initliaze call... if you need it, give it a more meaningful name perhaps?

uint256 public amountAllowedPerPeriod;
address public avatar;
uint256 public latestEthBalance;
mapping(uint256=>uint256) public totalAmountSentForPeriods;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totalAmountSentPerPeriod, a mapping from period indexes to amounts

uint256 public latestEthBalance;
mapping(uint256=>uint256) public totalAmountSentForPeriods;
uint256 public startBlock;
address public controller;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs some explanation, I think. So the constraint holds for what? it is a limit on how much the funds from the avatar the controller is allowed to spend per period.

}

/**
* @dev check the allowance of ether sent per period.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"and throws an error if the constraint is violated"

test/etherGC.js Outdated

await setup();
try {
await etherGC.initialize(avatar.address,20,web3.utils.toWei('5', "ether"),controller.address); //10 blocks ,5 eth
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment says 10 blocks, code says 20

/**
* @title EtherGC ether constraint per period
*/
contract EtherGC {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have a GlobalConstraint interface to inherit from?

address _avatar,
uint256 _constraintPeriodWindow,
uint256 _amountAllowedPerPeriod,
address _controller
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need the controller as a separate argument, can't you get that from the avatar_?

test/etherGC.js Outdated
await controller.sendEther(web3.utils.toWei('4', "ether"), accounts[2],avatar.address);
//send more than 10 eth
await web3.eth.sendTransaction({from:accounts[0],to:avatar.address, value: web3.utils.toWei('10', "ether")});
await controller.sendEther(web3.utils.toWei('4', "ether"), accounts[2],avatar.address);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to explain in a comment why this statement is not failing. Afaics, if this and the previous lines fall within the same period, you have sent 9 ether and violated the constraint. So by some coincidence, this last transfer happens in the next period?

@orenyodfat orenyodfat closed this May 22, 2020
@orenyodfat orenyodfat reopened this May 22, 2020
Oren Sokolowsky added 2 commits May 23, 2020 00:09
@orenyodfat orenyodfat changed the title etherGC.sol etherGC.sol +reputationGC.sol May 23, 2020
Copy link
Contributor

@leviadam leviadam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some comments. Mainly about time/blocks.
Mostly, looks ok.

/**
* @dev initialize
* @param _avatar the avatar to enforce the constraint on
* @param _periodLength the periodLength in blocks units
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think period should not be in blocks, as block time is changing.
The timestamp cannot be trusted up to seconds, but it can be for large periods, as in this case.

avatar = _avatar;
periodLength = _periodLength;
amountAllowedPerPeriod = _amountAllowedPerPeriod;
startBlock = block.number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start time/block is actually not really required, as you can pick any point in time to count from. But it makes the mapping more readable (start from index 0 instead of a random shift). Guessing it is worth the one-time 20k gas.

using SafeMath for uint256;

uint256 public periodLength; //the period length in blocks units
uint256 public amountAllowedPerPeriod;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this should be percentage-wise, or absolute values. Probably better to keep it absolute.

totalAmountSentPerPeriod[currentPeriodIndex] =
totalAmountSentPerPeriod[currentPeriodIndex].add(avatarBalanceBefore.sub(address(avatar).balance));
require(totalAmountSentPerPeriod[currentPeriodIndex] <= amountAllowedPerPeriod,
"Violation of Global constraint EtherGC:amount sent exceed in current period");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should set back avatarBalanceBefore to zero, as it will save gas.

contract ReputationGC is GlobalConstraintInterface {
using SafeMath for uint256;

uint256 public periodLength; //the period length in blocks units
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as in EtherGC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants